package com.visikard.asynctask;

import android.os.Handler;

import com.visikard.application.UIMessage;
import com.visikard.business.CouponBUS;
import com.visikard.response.RequestRTUICouponResponse;

public class RequestRTUICouponTask extends BaseTask {

	public static final int POS_MERCHANT_ID = 0;
	public static final int POS_TITLE = 1;
	public static final int POS_CONTRACT_NO = 2;
	public static final int POS_MESSAGE = 3;

	public RequestRTUICouponTask(Handler handler) {
		super(handler);
	}

	public RequestRTUICouponTask(Handler handler, boolean isShowProgress) {
		super(handler, isShowProgress);
	}

	@Override
	protected Object doBackgroundWork(Object... params) {
		// Get params
		long merchantId = (Long) params[POS_MERCHANT_ID];
		String title = (String) params[POS_TITLE];
		String contractNo = (String) params[POS_CONTRACT_NO];
		String message = (String) params[POS_MESSAGE];

		// call service
		CouponBUS busObj = new CouponBUS();
		return busObj.requestRTUICoupon(merchantId, title, contractNo, message);
	}

	@Override
	protected boolean handleResult(Object result) {
		RequestRTUICouponResponse response = (RequestRTUICouponResponse) result;
		if (response != null) {
			switch (response.getResult()) {
				case SUCCESS:
					mUIHandler.sendEmptyMessage(UIMessage.MSG_REQUEST_RTUI_COUPON_SUCCESS);
					return true;
				case FAILED:
					mUIHandler.sendEmptyMessage(UIMessage.MSG_REQUEST_RTUI_COUPON_FAILED);
					return true;
			}
		}
		return false;
	}

}
